/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number[]}
 */
var maxSlidingWindow = function (nums, k) {
    //单调队列
    let que = [],
        i = 0,
        n = nums.length;
    while(i<k){
        if(que.length==0) {
            que.push(nums[i])
            i++
            continue
        }
        while(true){
            if(que.length>0&&que[que.length-1]<nums[i]) {
                que.pop()
            }else {
                que.push(nums[i])
                break;
            }
        }
        i++
    }
    // console.log(que,'111');
    let res = [que[0]]
    for(let i = 1;i<n-k+1;i++){
        if(nums[i-1]==que[0]) que.shift()
        while(true){
            if(que.length>0&&que[que.length-1]<nums[i+k-1]){
                que.pop()
            }else{
                que.push(nums[i+k-1])
                break
            }
        }
    // console.log(que);
    res.push(que[0]) 
    }
    return res
};
//console.log(maxSlidingWindow([1,3,-1,-3,5,3,6,7],3));
